package com.opengroupe.entities;

// Generated 31 juil. 2012 15:46:15 by Hibernate Tools 3.4.0.CR1

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import com.opengroupe.util.QrhUtil;

/**
 * Candidatreponsequestion generated by hbm2java
 */
@Entity
@Table(name = "candidatreponsequestion", catalog = "qrh")
@NamedQuery(name="findCRQs", query="SELECT crq FROM CandidatReponseQuestion crq WHERE crq.candidat= ?1 and crq.question= ?2")
public class CandidatReponseQuestion implements java.io.Serializable {

	private static final long serialVersionUID = 8892437734923708564L;
	private CandidatReponseQuestionId id;
	private Candidat candidat;
	private Reponse reponse;
	private Question question;

	public CandidatReponseQuestion() {
	}

	public CandidatReponseQuestion(CandidatReponseQuestionId id,
			Candidat candidat, Reponse reponse, Question question) {
		this.id = id;
		this.candidat = candidat;
		this.reponse = reponse;
		this.question = question;
	}

	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "idCandidat", column = @Column(name = "idCandidat", nullable = false)),
			@AttributeOverride(name = "idQuestion", column = @Column(name = "idQuestion", nullable = false)),
			@AttributeOverride(name = "idReponse", column = @Column(name = "idReponse", nullable = false)) })
	public CandidatReponseQuestionId getId() {
		return this.id;
	}

	public void setId(CandidatReponseQuestionId id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "idCandidat", nullable = false, insertable = false, updatable = false)
	public Candidat getCandidat() {
		return this.candidat;
	}

	public void setCandidat(Candidat candidat) {
		this.candidat = candidat;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "idReponse", nullable = false, insertable = false, updatable = false)
	public Reponse getReponse() {
		return this.reponse;
	}

	public void setReponse(Reponse reponse) {
		this.reponse = reponse;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "idQuestion", nullable = false, insertable = false, updatable = false)
	public Question getQuestion() {
		return this.question;
	}

	public void setQuestion(Question question) {
		this.question = question;
	}

	@Override
	public String toString() {
		StringBuffer sbf = new StringBuffer("{");
		
		if(candidat != null) {
			sbf.append("\"emailCandidat\":\"");
			sbf.append(candidat.getEmailCandidat() + "\",");
		}
		
		if(question != null) {
			sbf.append("\"idQuestion\":");
			sbf.append(question.getIdQuestion() + ",");
			sbf.append("\"contenuQuestion\":\"");
			sbf.append(question.getContenuQuestion() + "\",");
		}
		
		if(reponse != null) {
			sbf.append("\"idReponse\":");
			sbf.append(reponse.getIdReponse() + ",");
			sbf.append("\"contenuReponse\":\"");
			sbf.append(reponse.getContenuReponse() + "\",");
		} 
		
		QrhUtil.deleteLastChar(sbf);
		
		sbf.append("}");
		
		return sbf.toString();
	}
}
